var express = require('express');
var app = express();
// var server = require('http').createServer(app);
var io = require('socket.io')(server);
var env = process.argv[2] || process.env.NODE_ENV || 'development';
var config = require('./config/config')[env];

app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By",' 3.2.1');
  next();
});

require('./config/express')(app, config);
require('./config/mongoose')(config);
require('./config/passport')();
require('./routes/index')(app);


console.log("Server running on port: " + config.port)
var faye = require('faye');
var http = require('http');
var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});
var server = http.createServer(app);




bayeux.attach(server)

// setInterval(function(){
//   bayeux.getClient().publish('/channel/1', {a:1})
// },1000)
require('./config/messagequeue')(bayeux);

server.listen(config.port);
